﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using System.Collections.Generic;
using System.Collections;
public partial class CardCenter_ChargetoCard : System.Web.UI.Page
{
    private WebUtility util;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Cards"] == null)
        {
            Response.Redirect("OnlinePurchaseCardStep1.aspx");
        }
        util = new WebUtility();
    }


    protected void ImgBtnTrans_Click(object sender, ImageClickEventArgs e)
    {
        string pCardNo = this.txt_FatherCardNo.Text;
        string pCardPwd = this.txt_FatherCardPwd.Text;

        if (String.IsNullOrEmpty(pCardNo) || String.IsNullOrEmpty(pCardPwd))
        {
            util.AlertMsg("输入不能为空!");
        }
        else 
        { 
            //---------------------------------------------------
            //并卡
            //构造子卡列表 
            List<Cards> subCardList = new List<Cards>();
            Cards[] cards =  (Cards[])Session["Cards"];
            if (cards != null && cards.Length > 0) 
            {
                for (int k = 0; k < cards.Length;k++ )
                {
                    subCardList.Add(cards[k]);
                }

                //构造一张父卡
                Cards fatherCard = new Cards();
                fatherCard.CardSeriaNumber = pCardNo;
                fatherCard.CardPassword = pCardPwd;
                //存错误信息列表
                List<string> errorList = new List<string>();
                // 显示结果
                BLL.CardsPointsTransfer transfer = new CardsPointsTransfer();
                errorList = transfer.Many2OneMergeCards(fatherCard, subCardList);

                if (errorList.Count > 0)
                {
                    util.AlertMsg("充值失败");
                    Session["Cards"] = null;
                }
                else 
                {
                    util.AlertMsg("充值成功");
                    Session["Cards"] = null;
                }

            }

          
            //----------------------------------------------------

        }
    }

}
